﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;

namespace FierceWar
{
    class Enemy : ElementalModel
    {
        public Vector3 _direction;
        
        private int _health;
        private int _count1 = 0;
		private int _count2 = 0;
		private int _velocity = 10;
        private Random rand = new Random();

        public Enemy(ContentManager content, ModelType modelType,
			Vector3 position, int velocity)
            : base(content, modelType)
        {
            Position = position;
			_velocity = velocity;
			_direction = new Vector3(rand.Next(_velocity), 0, rand.Next(-_velocity, 0));
            _health = 4;
            Rotation = new Vector3(0, _direction.Y, 0); ;
        }

        public bool IsShooted()
        {
            _health--;
            switch (_health)
            {
                case 3:
                    {
						Color = Color.Green;
                        break;
                    }
                case 2:
                    {
						Color = Color.Yellow;
                        break;
                    }
                case 1:
                    {
						Color = Color.Red;
                        break;
                    }
            }
            if (_health > 0)
            {
                return true;
            }
            else
                return false;
        }

        public void Update()
        {
            Position += _direction;
            _count1++;
            if (_count1 > 720)
            {
				_direction = new Vector3(rand.Next(-_velocity, _velocity), 0,
					rand.Next(-_velocity, _velocity));
                Rotation = new Vector3(0, (float)Math.Atan(_direction.X / _direction.Z), 0);
                _count1 = 0;
            }

			_count2++;
			if (_count2 > 1200)
			{
				Position += new Vector3(0.0f, rand.Next(-100, 100), 0.0f);
				_count2 = 0;
			}

            if (Position.Y < 0 || Position.Y > 30000)
            {
                _direction.Y = -_direction.Y;
                Rotation = new Vector3(0, _direction.Y, 0);
            }
            if (Position.X < -35536 || Position.X > 35536)
            {
                _direction.X = -_direction.X;
                Rotation = new Vector3(0, _direction.Y, 0);
            }
            if (Position.Z < -35536 || Position.Z > 35536)
            {
                _direction.Z = -_direction.Z;
                Rotation = new Vector3(0, _direction.Y, 0);
            }
        }
    }
}
